package com.xnewtech.xplatform.swan.system.modular.sys.controller;


import com.xnewtech.xplatform.swan.libs.scanner.annotation.GetResource;
import com.xnewtech.xplatform.swan.libs.scanner.stereotype.ApiResource;
import com.xnewtech.xplatform.swan.model.exp.RequestEmptyException;
import com.xnewtech.xplatform.swan.model.web.response.ResponseData;
import com.xnewtech.xplatform.swan.system.modular.sys.service.SysDashBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页统计展示Dashboard控制器
 *
 * @author xnew
 * @Date 2020/10/26 14:40
 */
@RestController
@ApiResource(name = "首页DashBoard接口", path = "/dashboard")
@Api(tags = "首页DashBoard接口")
public class DashBoardController {

    @Autowired
    private SysDashBoardService sysDashBoardService;

    @GetResource(name = "获取DashBoard模块统计数据", path = "/getModulesStatistics")
    @ApiOperation("获取DashBoard模块统计数据")
    public ResponseData getModulesStatistics(){
        List<Map<String,Object>> results = this.sysDashBoardService.modulesStatistics();
        return ResponseData.success(results);
    }


    @GetResource(name = "获取DashBoard业务统计数据", path = "/getBizStatistics")
    @ApiOperation("获取DashBoard模块统计数据")
    public ResponseData getBizStatistics(@RequestParam(value = "cycle") String cycle){
        if (cycle == null) {
            throw new RequestEmptyException("统计周期不能为空！");
        }
        Map<String,Object> result = this.sysDashBoardService.bizStatistics(cycle);
        return ResponseData.success(result);
    }
}
